package calculadoraplugin.actions;

import java.awt.event.ActionEvent;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.wb.swt.SWTResourceManager;

public class Calcular implements IWorkbenchWindowActionDelegate {
	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// Calcular calcular = new Calcular();
	}

	// JTextArea display = new JTextArea(1, 20);

	protected Shell shlCalculadora;
	private Text text;
	private IWorkbenchWindow window;

	public void actionPerformed(ActionEvent ae) {

	}

	/**
	 * Create contents of the window.
	 * 
	 * @wbp.parser.entryPoint
	 */
	protected void createContents() {
		shlCalculadora = new Shell();
		shlCalculadora
				.setImage(SWTResourceManager
						.getImage("D:\\Programacion Java\\calculadoraPlugin\\icons\\calculator.png"));
		shlCalculadora.setSize(310, 265);
		shlCalculadora.setText("Calculadora");

		Group group = new Group(shlCalculadora, SWT.NONE);
		group.setBounds(20, 88, 125, 135);

		Button btnNumero1 = new Button(group, SWT.NONE);
		btnNumero1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Hola");
			}
		});
		btnNumero1
				.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		btnNumero1.setBounds(10, 21, 30, 23);
		btnNumero1.setText("1");

		Button btnNumero2 = new Button(group, SWT.NONE);
		btnNumero2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		btnNumero2
				.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		btnNumero2.setBounds(46, 21, 30, 23);
		btnNumero2.setText("2");

		Button btnNewButton_1 = new Button(group, SWT.NONE);
		btnNewButton_1.setFont(SWTResourceManager.getFont("Tahoma", 11,
				SWT.NORMAL));
		btnNewButton_1.setBounds(86, 21, 30, 23);
		btnNewButton_1.setText("3");

		Button button_1 = new Button(group, SWT.NONE);
		button_1.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_1.setBounds(10, 51, 30, 23);
		button_1.setText("4");

		Button btnNewButton_2 = new Button(group, SWT.NONE);
		btnNewButton_2.setFont(SWTResourceManager.getFont("Tahoma", 11,
				SWT.NORMAL));
		btnNewButton_2.setBounds(46, 51, 30, 23);
		btnNewButton_2.setText("5");

		Button button_2 = new Button(group, SWT.NONE);
		button_2.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_2.setBounds(86, 50, 30, 23);
		button_2.setText("6");

		Button button_3 = new Button(group, SWT.NONE);
		button_3.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_3.setBounds(10, 80, 30, 23);
		button_3.setText("7");

		Button button_4 = new Button(group, SWT.NONE);
		button_4.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_4.setText("8");
		button_4.setBounds(46, 80, 30, 23);

		Button button_5 = new Button(group, SWT.NONE);
		button_5.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_5.setText("9");
		button_5.setBounds(86, 79, 30, 24);

		Button button_6 = new Button(group, SWT.NONE);
		button_6.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_6.setText("0");
		button_6.setBounds(10, 109, 30, 23);

		Button button_7 = new Button(group, SWT.NONE);
		button_7.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_7.setText(",");
		button_7.setBounds(86, 109, 30, 23);

		Button button_12 = new Button(group, SWT.NONE);
		button_12.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_12.setText("+/-");
		button_12.setBounds(46, 109, 30, 23);
		group.setTabList(new Control[] { btnNumero1, btnNumero2,
				btnNewButton_1, button_1, btnNewButton_2, button_2, button_3,
				button_4, button_5, button_6, button_12, button_7 });

		Group group_1 = new Group(shlCalculadora, SWT.NONE);
		group_1.setBounds(151, 88, 136, 137);

		Button btnNewButton_3 = new Button(group_1, SWT.NONE);
		btnNewButton_3.setFont(SWTResourceManager.getFont("Tahoma", 11,
				SWT.NORMAL));
		btnNewButton_3.setBounds(10, 24, 68, 23);
		btnNewButton_3.setText("/");

		Button button_8 = new Button(group_1, SWT.NONE);
		button_8.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_8.setText("*");
		button_8.setBounds(10, 53, 68, 23);

		Button button_9 = new Button(group_1, SWT.NONE);
		button_9.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_9.setText("-");
		button_9.setBounds(10, 82, 68, 23);

		Button button_10 = new Button(group_1, SWT.NONE);
		button_10.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_10.setText("+");
		button_10.setBounds(10, 111, 68, 23);

		Button button_11 = new Button(group_1, SWT.NONE);
		button_11.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		button_11.setText("=");
		button_11.setBounds(85, 24, 41, 110);

		Group group_2 = new Group(shlCalculadora, SWT.NONE);
		group_2.setBounds(20, 35, 267, 47);

		Button btnCe = new Button(group_2, SWT.NONE);
		btnCe.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		btnCe.setText("CE");
		btnCe.setBounds(187, 14, 30, 23);

		Button btnC = new Button(group_2, SWT.NONE);
		btnC.setFont(SWTResourceManager.getFont("Tahoma", 11, SWT.NORMAL));
		btnC.setText("C");
		btnC.setBounds(227, 14, 30, 23);
		group_2.setTabList(new Control[] { btnC, btnCe });

		Label label = new Label(shlCalculadora, SWT.SEPARATOR | SWT.HORIZONTAL);
		label.setBounds(10, 88, 277, 2);

		text = new Text(shlCalculadora, SWT.BORDER);
		text.setBounds(20, 10, 267, 19);

		// display.setEditable(false);
		// display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		// display.setBounds(20, 10, 267, 19);
		// shlCalculadora.addControlListener((ControlListener) display);

		shlCalculadora.setTabList(new Control[] { group, group_1, group_2 });

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	/**
	 * @wbp.parser.entryPoint
	 */
	@Override
	public void init(IWorkbenchWindow arg0) {

		Calcular window = new Calcular();
		window.open();

	}

	/**
	 * Open the window.
	 * 
	 * @wbp.parser.entryPoint
	 */
	public void open() {
		/*
		 * Display display = Display.getDefault(); createContents();
		 * shell.open(); shell.layout(); while (!shell.isDisposed()) { if
		 * (!display.readAndDispatch()) { display.sleep(); } }
		 */
	}

	/**
	 * @wbp.parser.entryPoint
	 */
	@Override
	public void run(IAction arg0) {
		// TODO Auto-generated method stub
		Display display = Display.getDefault();
		createContents();
		shlCalculadora.open();
		shlCalculadora.layout();
		while (!shlCalculadora.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	@Override
	public void selectionChanged(IAction arg0, ISelection arg1) {
		// TODO Auto-generated method stub

	}
}
